import 'package:cupertino_store/cart_tab.dart';
import 'package:cupertino_store/product_list_tab.dart';
import 'package:cupertino_store/search_tab.dart';
import 'package:flutter/cupertino.dart';



// class CupertinoStoreHomePage extends StatelessWidget {
//   const CupertinoStoreHomePage({super.key});
//   @override
//   Widget build(BuildContext context) {
//     return CupertinoTabScaffold(
//       tabBar: CupertinoTabBar(
//         items: const <BottomNavigationBarItem> [
//            BottomNavigationBarItem(
//             icon: Icon(CupertinoIcons.home),
//             label: 'Products',
//           ),
//           BottomNavigationBarItem(
//             icon: Icon(CupertinoIcons.search),
//             label: 'Search',
//           ),
//           BottomNavigationBarItem(
//             icon: Icon(CupertinoIcons.shopping_cart),
//             label: 'Cart',
//           ),
//         ],
//       ),

//       tabBuilder: (context, index) {
//         switch (index) {
//           case 1:
//             return CupertinoTabView(builder: (context) {
//               return CupertinoPageScaffold(
//                 child: ProductListTab(),
//               );
//             });
//           case 2:
//            return CupertinoTabView(builder: (context) {
//               return CupertinoPageScaffold(
//                 child: ProductListTab(),
//               );
//             });
//           case 3:
//            return CupertinoTabView(builder: (context) {
//               return CupertinoPageScaffold(
//                 child: ProductListTab(),
//               );
//             });  
//         }
//       },
      
  
//     );
//   }
// }

class CupertinoStoreHomePage extends StatelessWidget {
  const CupertinoStoreHomePage({super.key});
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(CupertinoIcons.home),
            label: 'Products',
          ),
          BottomNavigationBarItem(
            icon: Icon(CupertinoIcons.search),
            label: 'Search',
          ),
          BottomNavigationBarItem(
            icon: Icon(CupertinoIcons.shopping_cart),
            label: 'Cart',
          ),
        ],
      ),

      //构建页面
      tabBuilder: (BuildContext context, int index) {
        late final CupertinoTabView tabView;
        switch (index) {
          case 0:
           tabView = CupertinoTabView(builder: (context) {
              return CupertinoPageScaffold(
                child: ProductListTab(),
              );
            });
            break;
          case 1:
            tabView = CupertinoTabView(builder: (context) {
              return const CupertinoPageScaffold(
                child: SearchTab(),
              );
            });
            break;
          case 2:
            tabView = CupertinoTabView(builder: (context) {
              return const CupertinoPageScaffold(
                child: ShoppingCartTab(),
              );
            });
            break;
        }
        return tabView;
      },
    );
  }
}